package com.ender.springboot.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean(name = "hello")
    public Queue helloQueue() {
        return new Queue("hello");
    }

    @Bean(name = "log")
    public Queue logQueue() {
        return new Queue("log");
    }

    @Bean(name = "pushMovie")
    public Queue pushMovieQueue() {
        return new Queue("push.pushmovie");
    }
    @Bean(name = "pushSeries")
    public Queue pushSeriesQueue() {
        return new Queue("push.pushseries");
    }

    @Bean
    public FanoutExchange logExchange() {
        return new FanoutExchange("fanoutExchange");
    }

    @Bean
    public TopicExchange exchange() {
        return new TopicExchange("topicExchange");
    }

    @Bean
    public Binding bindingTopicMovieExchange(@Qualifier("pushMovie") Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("push.#");//*表示一个词，#表示0个或多个词
    }

    @Bean
    public Binding bindingTopicSeriesExchange(@Qualifier("pushSeries") Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("push.#");//*表示一个词，#表示0个或多个词
    }

    @Bean
    public Binding bindingHelloFanoutExchange(@Qualifier("hello") Queue queue, FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }
    @Bean
    public Binding bindingLogFanoutExchange(@Qualifier("pushMovie") Queue queue, FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }
    @Bean
    public Binding bindingPushMovieFanoutExchange(@Qualifier("pushSeries") Queue queue, FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }
    @Bean
    public Binding bindingPushSeriesFanoutExchange(@Qualifier("log") Queue queue, FanoutExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange);
    }

}

